//
//  MainAccountBtnCell.swift
//  d11
//
//  Created by peale on 2018/9/17.
//  Copyright © 2018年 Tech_001. All rights reserved.
//

import UIKit
typealias AccountInBlock = () -> Void
class MainAccountBtnCell: UITableViewCell {
    var accountInBlock: AccountInBlock?
    func callInClickBlock(_ block: @escaping AccountInBlock) {
        
        accountInBlock = block
    }
    var bgImgView : UIImageView?
    var  intoBtn :UIButton?
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
         self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setUpUI() -> Void {
        self.backgroundColor  = UIColor.clear
        self.selectionStyle = UITableViewCell.SelectionStyle.none
        self.bgImgView = UIImageView.init()
        self.bgImgView?.image = imageNamed("icon_my_cell_bottom")
         self.bgImgView?.isUserInteractionEnabled = true
        self.contentView.addSubview(bgImgView!);
        self.bgImgView?.snp.makeConstraints{(make) in
            make.width.equalToSuperview().offset(-10)
            make.height.equalTo(115)
            make.centerX.equalTo(self.contentView)
        }
        
        self.intoBtn = UIButton.init(type: .custom)
        self.intoBtn?.layer.masksToBounds = true
        self.intoBtn?.layer.cornerRadius = 5
        self.intoBtn?.backgroundColor = UIColor.white
        self.intoBtn?.layer.borderWidth = 1
        self.intoBtn?.titleLabel?.font = UIFont.systemFont(ofSize: 17)
        self.intoBtn?.layer.borderColor = HexRGBAlpha(0xFCD199, 1).cgColor
        self.intoBtn?.setTitleColor(HexRGBAlpha(0xFCD199, 1),for: .normal)
        self.intoBtn?.setTitle("一键回收", for: .normal)
        self.bgImgView?.addSubview(self.intoBtn!)
         self.intoBtn?.addTarget(self, action: #selector(self.actionToClick), for: .touchUpInside)
        self.intoBtn?.snp.makeConstraints{(make) in
            make.centerX.equalToSuperview()
            make.width.equalTo(200)
            make.top.equalTo(30)
            make.height.equalTo(40)
        }
    }
    
    func setData(index:Int) -> Void {
        if index == 0 {
            self.intoBtn?.layer.borderColor = HexRGBAlpha(0xBBBEBF, 1).cgColor
            self.intoBtn?.setTitleColor(HexRGBAlpha(0xBBBEBF, 1),for: .normal)
        }else{
            self.intoBtn?.layer.borderColor = HexRGBAlpha(0xFCD199, 1).cgColor
            self.intoBtn?.setTitleColor(HexRGBAlpha(0xFCD199, 1),for: .normal)
        }
    }
    
    @objc func actionToClick() -> Void {
        if accountInBlock != nil {
            accountInBlock!()
        }
    }
}
